var MAX_COUNT = 6144;
exports.MAX_COUNT = MAX_COUNT;

// ----------------
// numberFormat
// ----------------
exports.numberFormat = function (count) {
    count = count + '';
    var end = count.length - 1;
    var number = [];
    var p = 0;
    while (end > -1) {
        if (p == 3) {
            p = 0;
            number.unshift(',')
        }
        number.unshift(count.charAt(end));
        p++;
        end--;
    }
    return number.join('');
};

// ----------------
// return score
// ----------------
exports.getBonus = function (count) {
    if (count < 3) {
        return 0;
    }

    var bonus = 3;
    count /= 3;
    while (count > 1) {
        count = count >> 1;
        bonus *= 3;
    }
    return bonus;
};

// ---------------- get 2^x
exports.getScoreOrder = function (count) {
    if (count <= 3) {
        return 0;
    }
    var order = 0;
    count /= 3;
    while (count > 1) {
        count = count >> 1;
        order++;
    }
    return order;
};

exports.canMerge = function (previous, current) {
    if (previous + current == 3) {
        return true;
    }
    if (previous >= MAX_COUNT || current >= MAX_COUNT) {
        return false;
    }
    if (previous == current && previous + current >= 6) {
        return true;
    }
    return false;
};
